package com.zrwl.poscloud.core.restapi.admin.baseInfo;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.xo.service.AdminService;
import com.zrwl.poscloud.xo.service.DeptAdminRService;
import com.zrwl.poscloud.xo.service.TeacherAdminRService;
import com.zrwl.poscloud.xo.vo.TeacherAdminRVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zrwl.poscloud.xo.service.TransitSendService;
import com.zrwl.poscloud.xo.vo.TransitSendVO;
/**
 * 出校通知 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-17
 */
@RestController
@Api(value = "出校通知相关接口", tags = {"出校通知相关接口"})
@RequestMapping("/transitSend")
@Slf4j
public class TransitSendRestApi {
    @Autowired
    private TransitSendService transitSendService;
    @Autowired
    private DeptAdminRService deptAdminRService;
    @Autowired
    private TeacherAdminRService teacherAdminRService;
    @Autowired
    private AdminService adminService;
    @AuthorityVerify
    @ApiOperation(value = "获取出校通知列表", notes = "获取出校通知列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody TransitSendVO transitSendVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取出校通知列表: {}", transitSendVO);
        TeacherAdminRVO currentTeacher = teacherAdminRService.getCurrentTeacher();
        if(currentTeacher == null){
            transitSendVO.setDeptRoleTree(deptAdminRService.getMyDeptRoleTreeCode());
        }else {
            transitSendVO.setDeptRoleTree(currentTeacher.getCompanyCodeAll().split(","));
        }
        return ResultUtil.successWithData(transitSendService.getPageList(transitSendVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取出校通知列表", notes = "获取出校通知列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody TransitSendVO transitSendVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取出校通知列表: {}", transitSendVO);
        return ResultUtil.successWithData(transitSendService.getAllList(transitSendVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增出校通知")    @ApiOperation(value = "新增出校通知", notes = "新增出校通知", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody TransitSendVO transitSendVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增出校通知: {}", transitSendVO);
        return transitSendService.add(transitSendVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改出校通知")    @ApiOperation(value = "修改出校通知", notes = "修改出校通知", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody TransitSendVO transitSendVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改出校通知: {}", transitSendVO);
        return transitSendService.edit(transitSendVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "消息推送")    @ApiOperation(value = "消息推送", notes = "消息推送", response = String.class)
    @PostMapping("/messagePush")
    public String messagePush(@Validated({Update.class}) @RequestBody TransitSendVO transitSendVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("消息推送: {}", transitSendVO);
        transitSendVO.setCompanyUid(adminService.getMe().getCompanyUid());
        return transitSendService.messagePush(transitSendVO);
    }
    @AuthorityVerify
    @OperationLogger(value = "删除出校通知")    @ApiOperation(value = "删除出校通知", notes = "删除出校通知", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody TransitSendVO transitSendVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除出校通知: {}", transitSendVO);
        return transitSendService.delete(transitSendVO);
    }

}
